package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.Workflow;
import com.qidianit.mes.pro.service.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: YKYB
 * @Date: 2025/9/18 19:17
 * @Description:
 */
@RestController
@RequestMapping("/workflow")
public class WorkFlowController {
    @Autowired
    private WorkflowService workFlowService;

    @GetMapping("/selectByMaterialCode")
    public Result<List<Workflow>> selectByMaterialCode(String materialCode){
        return workFlowService.selectByMaterialCode(materialCode);
    }

    @GetMapping("/page")
    public Result<PageInfo<Workflow>> list(Workflow workFlow,
                                           @RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer size) {
        return workFlowService.selectList(workFlow, page, size);
    }

    @GetMapping("/code/{code}")
    public Result<Workflow> getByCode(@PathVariable("code") String code) {
        return workFlowService.selectByCode(code);
    }

    @PostMapping ("/add")
    public Result<Workflow> save(@RequestBody Workflow workFlow) {
        return workFlowService.saveWorkflow(workFlow);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody Workflow workFlow) {
        return workFlowService.updateById(workFlow);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id) {
        return workFlowService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDeleted(Long[] id) {
        return workFlowService.batchDeleted(id);
    }



}
